<?php

/**
 * 登录界面
 * ============================================================================
 * * 版权所有 2012 铭迈（上海）实业有限公司，并保留所有权利。
 * 网站地址: http://www.mingmailtd.com/；
 * ----------------------------------------------------------------------------
 * 仅用于公司内部人员使用。
 * ============================================================================
 * $Author: zhangmingming $
 * $Id: lib_smart.php 2012/6/25 15:34:03 $
 */

define('IN_MMOA', true);

require(dirname(__FILE__) . '/includes/init.php');

//未登录调整登录界面
if (empty($_SESSION['username']))
{
	header("Location: ./");
}

if ($_REQUEST['act'] == '')
{
	$smarty->assign('mm_show','loggedOn');
	$smarty->display('main.tpl');
} 
/* 框架顶部显示  */
elseif ($_REQUEST['act'] == 'top')
{
	$sql = "SELECT d.d_name FROM " . $mmoa->table('departments') . " AS d, " . $mmoa->table('employees') . " AS e " .
			" WHERE d.id = e.e_depart AND e.e_name = '" . $_SESSION['username'] . "'";
	$department = $db->getOne($sql);
	
	$sqlg = "SELECT e_group FROM " . $mmoa->table('employees') . " WHERE e_name = '" . $_SESSION['username'] . "'";
	$egroup = $db->getOne($sqlg);
	
	$smarty->assign('username', $_SESSION['username']);
	$smarty->assign('department', $department);
	$smarty->assign('egroup', $egroup);
	
	$smarty->assign('time', date("Y-m-d H:i:s	l"));
	
	clear_caches();
	$smarty->display('top.tpl');
}
/* 框架左侧显示  */
elseif ($_REQUEST['act'] == 'menu')
{
	// 权限判断
	$u = $_SESSION['username'];
	$sql = "SELECT e_depart, e_group FROM " . $mmoa->table('employees') . " WHERE e_name = '$u'";
	$uinfo = $db->getRow($sql);
	if ($uinfo){
		$d = $uinfo['e_depart'];
		$g = $uinfo['e_group'];
		
		$sqld = "SELECT d_name FROM " . $mmoa->table('departments') . " WHERE id = $d";
		$dname = $db->getOne($sqld);
		if ($dname == '管理部'){
			$priv = true; 
			$priv_dev = true;
		} elseif ($dname == '行政部' && $g == '部门经理') {
			$priv = true;
			$priv_dev = false;
		} elseif ($dname == '技术部' && $g == '部门经理') {
			$priv = false;
			$priv_dev = true;
		} else {
			$priv = false;
			$priv_dev = false;
		}

		$smarty->assign('priv', $priv);
		$smarty->assign('priv_dev', $priv_dev);
		
		// 技术部人员可以查看自己负责或者参与的项目
		if ($dname == '技术部'){
			$smarty->assign('in_project', 'true');
		}
	}
	
	clear_caches();
	$smarty->display('menu.tpl');
}
/* 框架主显示区  */
elseif ($_REQUEST['act'] == 'content')
{
	$ename = $_SESSION['username'];
	$sql = "SELECT e_group FROM " . $mmoa->table('employees') . " WHERE e_name = '$ename'";
	$egroup = $db->getOne($sql);
	
	$did = $_SESSION['department'];
	$sqld = "SELECT d_name FROM " . $mmoa->table('departments') . " WHERE id = '$did'";
	$edepart = $db->getOne($sqld);
	
	$smarty->assign('ename', $ename);
	$smarty->assign('edepart', $edepart);
	$smarty->assign('egroup', $egroup);
	
	clear_caches();
	$smarty->display('content.tpl');
}

/* 框架底部版权区  */
elseif ($_REQUEST['act'] == 'foot')
{
	//$smarty->display('foot.tpl');
}

?>